package Text1;

import java.util.*;

public class vertex {
    String name;
    List<edge> edges;
    boolean visited;
    int inpegree;

    public vertex(String name) {
        this.name = name;
        this.edges = new ArrayList<>();

    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public static void dfs(vertex v) {
        if(v==null){
            return;
        }
        v.visited=true;
        System.out.println(v.name);
        for (edge edge:v.edges) {
            if(!edge.linked.visited){
                dfs(edge.linked);
            }
        }
    }

    public static void dfs2(vertex v) {
        if(v==null){
            return;
        }
        Stack<vertex> stack = new Stack<>();
        stack.push(v);

        while (!stack.empty()){
           vertex vertex= stack.pop();
            vertex.visited=true;
            System.out.println(vertex.name);
            for (edge edge: vertex.edges) {
                if(!edge.linked.visited){

                    stack.push(edge.linked);
                }
            }
        }
    }

    public static void bfs(vertex v) {
        if(v==null){
            return;
        }
        Queue<vertex> queue=new LinkedList();
        queue.offer(v);
        v.visited=true;
        while (!queue.isEmpty()){
        vertex vertex=queue.poll();
            System.out.println(vertex.name);
        for(edge edge:vertex.edges){
            if(!edge.linked.visited){
                edge.linked.visited=true;
                queue.offer(edge.linked);
            }
        }
        }
    }
}
